package org.example.web;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class ProducerController {
    @Value("${server.port}")
    private String port;

    @GetMapping(value = "/do-get")
    public String doGet(@RequestParam("name") String name) throws InterruptedException {
        long holdOn = (long) (Math.random() * 1000);
//        long holdOn = 10000;
        Thread.sleep(holdOn);

        return "hi, " + name + "! doGet method from port: " + port;
    }

    @PostMapping(value = "/do-post")
    public String doPost(@RequestBody Map<String, Object> body) throws InterruptedException {
        long holdOn = (long) (Math.random() * 1000);
//        long holdOn = 10000;
        Thread.sleep(holdOn);

        return "hi, " + body.getOrDefault("name", "Stranger") + "! doPost method from port: " + port;
    }

}
